package com.neusoft.controller;

import com.neusoft.domain.Employee;
import com.neusoft.domain.PageResult;
import com.neusoft.domain.Result;
import com.neusoft.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employees")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @GetMapping("/getEmployeeByPage")
    public Result getEmployeeByPage(@RequestParam("page") Integer pageNum,@RequestParam("size") Integer pageSize, String account, String nickname, String telephone){
        System.out.println("进入员工分页查询");
        System.out.println("pageNum:"+pageNum+"  pageSize:"+pageSize+"  account:"+account+"  nickname:"+nickname+"  telephone:"+telephone);
        PageResult<Employee> employeeByPage = employeeService.getEmployeeByPage(pageNum, pageSize, account, nickname, telephone);
        return Result.success(employeeByPage);
    }
    @PostMapping("/saveEmployee")
    public Result saveEmployee(@RequestBody Employee employee){
        System.out.println("进入员工添加");
        employeeService.saveEmployee(employee);
        return Result.success();
    }
    @PutMapping("/updateEmployee")
    public Result updateEmployee(@RequestBody Employee employee){
        System.out.println("进入员工修改");
        employeeService.updateEmployee(employee);
        return Result.success();
    }

    @PutMapping("/updateEmployeeStatus")
    public Result updateEmployeeStatus(@RequestBody Employee employee){
        System.out.println("id:"+employee.getId()+"  is_del:"+employee.getIs_del());
        System.out.println("进入员工状态修改");
        employeeService.updateEmployeeStatus(employee);
        return Result.success();
    }

}
